<template>
  <div class="zx-card">
    <div class="card-bg">
      <div class="caption">
        <h4>{{title}}</h4>
        <div class="card-No">
          <popup-radio :options="cardList" v-model="cardNo" >
            <p slot="popup-header" class="AccountTranDetail-card-slot">选择卡片</p>
          </popup-radio>
          <!--<img class="arrow-down" src="../../assets/img/arrowDownWhite.png" alt="">-->
        </div>
      </div>
      <div class="balance" >
        <p>{{byx}}</p>
        <span>余额</span><span>{{ balance | filterMoney }}元</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'zxButton',
  props: {
    cardList: {
      type: Array,
      default () {
        return ['9999 **** 9999', '8888 **** 8888', '7777 **** 7777']
      }
    },
    title: {
      type: String,
      default: '转出账号'
    }
  },
  data () {
    return {
      byx: '',
      nowCur: 0,
      cardNo: '',
      balance: 0,
      butTypea: 'primary',
      butTypeB: 'default'
    }
  },
  computed: {
    bringForwardInfo () {
      return this.$store.getters.getBringForwardInfo
    }
  },
  methods: {
    init () {
      // debugger
      if (this.bringForwardInfo.cardNo !== '') {
        this.cardNo = this.bringForwardInfo.cardNo
        this.getBalanceAmt()
      } else {
        if (this.cardList.length > 0) {
          this.cardNo = this.cardList[0]
          this.getBalanceAmt()
        }
      }
    },
    getBalanceAmt () {
      this.$bridge.callhandler('nativeRequest',
        JSON.stringify({
          'requstSource': 'internetRequest',
          'url': 'mstep.do?act=business',
          'params': {'method_Name': 'queryBalanceAmt', 'basic_Data': JSON.stringify({'cardNo': this.cardNo, 'currType': 'CNY'})}
        }),
        (response) => {
          // alert(response)
          // this.byx = response
          let rep = JSON.parse(response).data
          if (rep.head.respCode === '000000') {
            let lData = []
            lData[0] = this.cardNo
            lData[1] = this.balance
            this.balance = rep.body.balanceAmt
            this.$emit('on-change', lData)
          } else {
            this.$bridge.callhandler('showErrorHUD', {
              'type': 'toast',
              'errorMess': rep.head.respMsg
            })
          }
        })
    }
  },
  watch: {
    'cardNo': function (curVal, oldVal) {
      this.getBalanceAmt()
    }
  },
  mounted: function () {
    this.init()
  }
}
</script>
<style lang="less">
.zx-card {
  width: 100%;
  padding: .3rem .36rem;
  background-color: #f0f0f0;
  .card-bg {
    width: 6.78rem;
    padding: .34rem .28rem .26rem;
    margin: 0 auto;
    background-image: url('../../../static/img/cardBgm.png');
    -webkit-background-size: 100% auto;
    background-size: 100% 100%;
    color: #fff;
    .caption {
      display: flex;
      justify-content:space-between;
      align-items: center;
      font-size: 0.32rem;
      .card-No {
        .weui-cell {
          padding: 0;
        }
        .weui-cell_access .weui-cell__ft {
          padding-right: 0;
          .vux-cell-value {
            padding-right: .16rem;
            color: #ffffff;
            font-size: .28rem;
          }
        }
        & :after {
          position: relative;
          -webkit-transform: matrix(0.71, 0.71, 0.71, -0.71, 0, 0);
          transform: matrix(0.71, 0.71, 0.71, -0.71, 0, 0);
          top: -0.06rem;
        }
        .arrow-down {
          display: block;
          width: .22rem;
          margin-left: .16rem;
        }
      }
    }
    .balance {
      font-size: .28rem;
      text-align: right;
      margin-top: .22rem;
      padding-right:.38rem;
      span {
        margin-left: .1rem;
      }
    }
  }
}
/*弹出框*/
.AccountTranDetail-card-slot {
  position: relative;
  text-align: center;
  padding: .2rem 0;
}
.AccountTranDetail-card-slot:after {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-top: 1px solid #d9d9d9;
  color: #d9d9d9;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
}
</style>
